<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link type="text/css" rel="stylesheet" href="/public/static/H-ui/static/h-ui/css/H-ui.min.css"/>
    <link type="text/css" rel="stylesheet" href="/public/static/system/system.css">
    <title>Document</title>
    <style>
        body{ 
            padding: 50px;
        }
    </style>
</head>
<body>
    <div class="pt">
        <a href="javascript:history.back(-1);">&lt&lt返回签到列表</a>
    </div>
    <div>
        <fieldset class="fw">
            <h4 class="text-c stime" data-begin="{$signmsg.begin}" data-end="{$signmsg.end}">签到时间：{$signmsg.begin}~{$signmsg.end}</h4>
            <legend class="w">{$signmsg.sname}</legend>
            <button type="submit" class="btn btn-default btn-p size-L" data-id="{$signmsg.Id}" data-type="{$signmsg.type}">签到</button>
        </fieldset>
    </div>
    <script type="text/javascript" src="/public/static/H-ui/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="/public/static/H-ui/static/h-ui/js/H-ui.js"></script>
    <script type="text/javascript" src="/public/static/system/system.js"></script>
    <script>
        $(function(){
            let date = local_date();
            let begin = $('.stime').data('begin');
            let end = $('.stime').data('end');
            let Id = $('.btn').data('id');
            let Type = $('.btn').data('type')
            $.post(
                "{:url('issign')}",
                {
                    "Id":Id,
                    "type":Type,
                },
                function(res){   //回调函数
                    if(res.flag == 1){
                        console.log(res);
                        $(".btn").addClass("disabled");
                        $(".btn").html("已签到");
                    }else{
                        if(date<begin){
                            $(".btn").addClass("disabled");
                            $(".btn").html("不在签到时间段");
                        }else if(date>end){
                            $(".btn").addClass("disabled");
                            $(".btn").html("签到时间已过");
                        }
                    }
                },"json"
            )
        })
        
        $('.btn').click(function(){
            let sign_Time = local_date();
            let Id = $(this).data('id');
            let Type = $(this).data('type')
            $.post(
                "{:url('dosign')}",//走到哪里去
                {
                    "Id":Id,
                    "type":Type,
                    "sign_Time":sign_Time
                },
                function(res){   //回调函数
                    if(res.flag == 1){
                        console.log(res);
                        $(".btn").addClass("disabled");
                        $(".btn").html("已签到");
                    }else{
                        alert('签到失败')
                    }
                },"json"
            );   
        })
    </script>
</body>
</html>